#ifndef __physics_manager__h__
#define __physics_manager__h__

#include "global.h"
#include "singleton.h"
#include "entity.h"

enum
{
	COLLISION_TYPE_ENTITY = 1
};

class physics_manager : public singleton<physics_manager>
{
public:
    physics_manager();
	~physics_manager();
	cpSpace* get_space();
	void set_screen_bound(cpVect lt, cpVect rb);
	void update_physics_logic(float dt);
	void add_entity_to_space(entity* e);
	cpBody* physics_manager::make_body(float mass, float x, float y, float radius);
	cpShape* make_circle_shape(float radius, float elasticity, float friction, cpBody* body);
	cpShape* make_poly_shape(int vertex_count, cpVect* vertexs, float elasticity, float friction, cpBody* body);
    void left_mouse_down();
	void left_mouse_up();

	//
	void update_mouse_body();

	//
	bool shape_query(cpShape* s, float x, float y);

	//
	void release_all_force();

	//
	void delete_entity_from_space(entity* e);

	//
	static int body_collide_handle(cpArbiter *arb, struct cpSpace *space, void *data);


private:
	cpSpace* space;
	cpConstraint *mouseJoint;
	cpBody* mouseBody;
	cpVect mousePoint_last;
	float mx;
	float my;
};
#endif